<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="org.assistant.csp.data.Global"%>
<%@ page import="org.assistant.csp.data.UserSession"%>
<%@ page import="my.assistant.homecashmanager.inoutitem.data.DmInoutItem"%>
<%@ page import="my.assistant.homecashmanager.account.data.AccountBase"%>
<%@ page import="org.assistant.csp.data.RelationUser"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%
	UserSession userSession = (UserSession) request.getSession().getAttribute(Global.CURRENT_USER);

	List<DmInoutItem> dmInoutItemList = (List<DmInoutItem>)request.getAttribute("dmInoutItemList");
	Map<String,AccountBase> accountMap = (Map<String,AccountBase>)request.getAttribute("accountMap");
	List<RelationUser> relationUserList = (List<RelationUser>)request.getAttribute("relationUserList");
%>
<div style="text-align: left">
<input type="button" id="btn_query" name="btn_query" value="查询" class="ui-button ui-state-default ui-corner-all"></input>
<input type="button" id="btn_in" name="btn_in" value="收入" class="ui-button ui-state-default ui-corner-all"></input>
<input type="button" id="btn_out" name="btn_out" value="支出" class="ui-button ui-state-default ui-corner-all"></input>
<input type="button" id="btn_access" name="btn_access" value="存/取款" class="ui-button ui-state-default ui-corner-all"></input>
<input type="button" id="btn_transfer" name="btn_transfer" value="还信用卡/转账" class="ui-button ui-state-default ui-corner-all"></input>
<input type="button" id="btn_debt" name="btn_debt" value="借入" class="ui-button ui-state-default ui-corner-all"></input>
<input type="button" id="btn_claim" name="btn_claim" value="借出" class="ui-button ui-state-default ui-corner-all"></input>
</div>

<div id="dialog_in" style="display: none;" title="收入对话框">
	<p id="in_validateTips" style="color: #FF0000"></p>
	
	<form method="POST">
	<table cellspacing="0" class="yui-skin-sam noborder_table">
	<tbody>
		<tr>
			<th width="33%"><label for="in_dealDate"><font color="#FF0000">*&nbsp;</font>收入日期:</label></th>
			<td width="33%"><input type="text" id="in_dealDate" name="in_dealDate" maxlength="10" onclick="WdatePicker()" readonly="readonly" class="text ui-widget-content ui-corner-all"/>
				<input type="hidden" id="in_id" name="in_id" value="-1"/>
			</td>
			<td width="33%" class="memoText">格式：yyyy-MM-dd</td>
		</tr>
		<tr>
			<th><label for="in_inoutItem"><font color="#FF0000">*&nbsp;</font>收入项目:</label></th>
			<td>
				<select id="in_inoutItem" name="in_inoutItem" style="width: 100%" class="text ui-widget-content ui-corner-all">
					<option value="-1" selected="selected">请选择……</option>
					<%
					for(int i=0; i<dmInoutItemList.size(); i++){
						DmInoutItem dm = (DmInoutItem)dmInoutItemList.get(i);
						if("1".equals(dm.getInouttype())){// 收支项目类型，1:收入;0:支出;2:存取款;3:转账
							if(!dm.isLeaf()){
					%>
								<optgroup style="">(<%=dm.getName()%>下的子项目)</optgroup>
					<%
							}
					%>
							<option value="<%=dm.getId()%>" style="color:#0000FF"><%=dm.getName()%></option>
					<%
						}
					}
					%>
				</select>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="in_money"><font color="#FF0000">*&nbsp;</font>收入金额:</label></th>
			<td><input type="text" id="in_money" name="in_money" maxlength="10" onblur="moneyOnBlur('in_money','in_validateTips')" class="digital text ui-widget-content ui-corner-all"/></td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="in_account"><font color="#FF0000">*&nbsp;</font>收入账户:</label></th>
			<td>
				<select id="in_account" name="in_account" style="width: 100%" class="text ui-widget-content ui-corner-all">
					<option value="-1" selected="selected">请选择……</option>
					<%
						for(Iterator<AccountBase> it = accountMap.values().iterator(); it.hasNext();){
							AccountBase accountBase = (AccountBase)it.next();
							if(!"1".equals(accountBase.getType()) && !"2".equals(accountBase.getType())){// 账户类型：1.现金账户；2.银行账户；3.债权债务账户
								continue;
							}
					%>
							<option value="<%=accountBase.getId()%>"><%=accountBase.getName()%></option>
					<%
						}
					%>
				</select>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="in_relationUser"><font color="#FF0000">*&nbsp;</font>收入人:</label></th>
			<td>
				<select id="in_relationUser" name="in_relationUser" style="width: 100%" class="text ui-widget-content ui-corner-all">
				<%
				for(int i=0; i<relationUserList.size(); i++){
					RelationUser relationUser = (RelationUser)relationUserList.get(i);
					if(relationUser.getId().equals(userSession.getId())){
				%>
						<option value="<%=relationUser.getId()%>" selected="selected"><%=relationUser.getName()%></option>
				<%
					}else{
				%>
						<option value="<%=relationUser.getId()%>"><%=relationUser.getName()%></option>
				<%
					}
				}
				%>
				</select>
			</td>
			<td class="memoText">产生此收入项目的人</td>
		</tr>
		<tr>
			<th><label for="in_memo">备注:</label></th>
			<td><textarea id="in_memo" name="in_memo" rows="2" cols="18" class="text ui-widget-content ui-corner-all"></textarea></td>
			<td class="memoText"></td>
		</tr>
	</tbody>
	</table>
	</form>
</div><!-- 收入对话框 -->

<div id="dialog_out" style="display: none;" title="支出对话框">
	<p id="out_validateTips" style="color: #FF0000"></p>
	
	<form method="POST">
	<table cellspacing="0" class="yui-skin-sam noborder_table">
	<tbody>
		<tr>
			<th width="33%"><label for="out_dealDate"><font color="#FF0000">*&nbsp;</font>支出日期:</label></th>
			<td width="33%"><input type="text" id="out_dealDate" name="out_dealDate" maxlength="10" onclick="WdatePicker()" readonly="readonly" class="text ui-widget-content ui-corner-all"/>
				<input type="hidden" id="out_id" name="out_id" value="-1"/>
			</td>
			<td width="33%" class="memoText">格式：yyyy-MM-dd</td>
		</tr>
		<tr>
			<th><label for="out_inoutItem"><font color="#FF0000">*&nbsp;</font>支出项目:</label></th>
			<td>
				<select id="out_inoutItem" name="out_inoutItem" style="width: 100%" class="text ui-widget-content ui-corner-all">
					<option value="-1" selected="selected">请选择……</option>
					<%
					for(int i=0; i<dmInoutItemList.size(); i++){
						DmInoutItem dm = (DmInoutItem)dmInoutItemList.get(i);
						if("0".equals(dm.getInouttype())){// 收支项目类型，1:收入;0:支出;2:存取款;3:转账
							if(!dm.isLeaf()){
					%>
								<optgroup style="">(<%=dm.getName()%>下的子项目)</optgroup>
					<%
							}
					%>
							<option value="<%=dm.getId()%>" style="color:#FF0000"><%=dm.getName()%></option>
					<%
						}
					}
					%>
				</select>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="out_money"><font color="#FF0000">*&nbsp;</font>支出金额:</label></th>
			<td><input type="text" id="out_money" name="out_money" maxlength="10" onblur="moneyOnBlur('out_money','out_validateTips')" class="digital text ui-widget-content ui-corner-all"/></td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="out_account"><font color="#FF0000">*&nbsp;</font>支出账户:</label></th>
			<td>
				<select id="out_account" name="out_account" style="width: 100%" class="text ui-widget-content ui-corner-all">
					<option value="-1" selected="selected">请选择……</option>
					<%
						for(Iterator<AccountBase> it = accountMap.values().iterator(); it.hasNext();){
							AccountBase accountBase = (AccountBase)it.next();
							if(!"1".equals(accountBase.getType()) && !"2".equals(accountBase.getType())){// 账户类型：1.现金账户；2.银行账户；3.债权债务账户
								continue;
							}
					%>
							<option value="<%=accountBase.getId()%>"><%=accountBase.getName()%></option>
					<%
						}
					%>
				</select>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="out_relationUser"><font color="#FF0000">*&nbsp;</font>支出人:</label></th>
			<td>
				<select id="out_relationUser" name="out_relationUser" style="width: 100%" class="text ui-widget-content ui-corner-all">
				<%
				for(int i=0; i<relationUserList.size(); i++){
					RelationUser relationUser = (RelationUser)relationUserList.get(i);
					if(relationUser.getId().equals(userSession.getId())){
				%>
						<option value="<%=relationUser.getId()%>" selected="selected"><%=relationUser.getName()%></option>
				<%
					}else{
				%>
						<option value="<%=relationUser.getId()%>"><%=relationUser.getName()%></option>
				<%
					}
				}
				%>
				</select>
			</td>
			<td class="memoText">产生此支出项目的人</td>
		</tr>
		<tr>
			<th><label for="out_memo">备注:</label></th>
			<td><textarea id="out_memo" name="out_memo" rows="2" cols="18" class="text ui-widget-content ui-corner-all"></textarea></td>
			<td class="memoText"></td>
		</tr>
	</tbody>
	</table>
	</form>
</div><!-- 支出对话框 -->

<div id="dialog_access" style="display: none;" title="存/取款对话框">
	<p id="access_validateTips" style="color: #FF0000"></p>
	
	<form method="POST">
	<table cellspacing="0" class="yui-skin-sam noborder_table">
	<tbody>
		<tr>
			<th width="33%"><label for="access_dealDate"><font color="#FF0000">*&nbsp;</font>存/取款日期:</label></th>
			<td width="33%"><input type="text" id="access_dealDate" name="access_dealDate" maxlength="10" onclick="WdatePicker()" readonly="readonly" class="text ui-widget-content ui-corner-all"/>
				<input type="hidden" id="access_id" name="access_id" value="-1"/>
			</td>
			<td width="33%" class="memoText">格式：yyyy-MM-dd</td>
		</tr>
		<tr>
			<th><label for="access_inoutItem"><font color="#FF0000">*&nbsp;</font>存取类型</label></th>
			<td>
				<input type="radio" id="access_inoutItem_1" name="access_inoutItem_" value="1" onclick="document.getElementById('access_inoutItem').value=1;" checked/>取款
				<input type="radio" id="access_inoutItem_2" name="access_inoutItem_" value="2" onclick="document.getElementById('access_inoutItem').value=2;"/>存款
				<input type="hidden" id="access_inoutItem" name="access_inoutItem" value="1"/>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="access_money"><font color="#FF0000">*&nbsp;</font>存取金额:</label></th>
			<td><input type="text" id="access_money" name=access_money maxlength="10" onblur="moneyOnBlur('in_money','in_validateTips')" class="digital text ui-widget-content ui-corner-all"/></td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="access_cash_account"><font color="#FF0000">*&nbsp;</font>现金账户:</label></th>
			<td>
				<select id="access_cash_account" name="access_cash_account" style="width: 100%">
					<%
						for(Iterator<AccountBase> it = accountMap.values().iterator(); it.hasNext();){
							AccountBase accountBase = (AccountBase)it.next();
							if(!"1".equals(accountBase.getType())){// 账户类型：1.现金账户；2.银行账户；3.债权债务账户
								continue;
							}
					%>
							<option value="<%=accountBase.getId()%>"><%=accountBase.getName()%></option>
					<%
						}
					%>
				</select>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="access_bank_account"><font color="#FF0000">*&nbsp;</font>银行账户:</label></th>
			<td>
				<select id="access_bank_account" name="access_bank_account" style="width: 100%">
					<%
						for(Iterator<AccountBase> it = accountMap.values().iterator(); it.hasNext();){
							AccountBase accountBase = (AccountBase)it.next();
							if(!"2".equals(accountBase.getType())){// 账户类型：1.现金账户；2.银行账户；3.债权债务账户
								continue;
							}
					%>
							<option value="<%=accountBase.getId()%>"><%=accountBase.getName()%></option>
					<%
						}
					%>
				</select>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="access_relationUser"><font color="#FF0000">*&nbsp;</font>存/取款人:</label></th>
			<td>
				<select id="access_relationUser" name="access_relationUser" style="width: 100%" class="text ui-widget-content ui-corner-all">
				<%
				for(int i=0; i<relationUserList.size(); i++){
					RelationUser relationUser = (RelationUser)relationUserList.get(i);
					if(relationUser.getId().equals(userSession.getId())){
				%>
						<option value="<%=relationUser.getId()%>" selected="selected"><%=relationUser.getName()%></option>
				<%
					}else{
				%>
						<option value="<%=relationUser.getId()%>"><%=relationUser.getName()%></option>
				<%
					}
				}
				%>
				</select>
			</td>
			<td class="memoText">产生此存/取款项目的人</td>
		</tr>
		<tr>
			<th><label for="access_memo">备注:</label></th>
			<td><textarea id="access_memo" name="access_memo" rows="2" cols="18" class="text ui-widget-content ui-corner-all"></textarea></td>
			<td class="memoText"></td>
		</tr>
	</tbody>
	</table>
	</form>
</div><!-- 存取款对话框 -->

<div id="dialog_transfer" style="display: none;" title="转账对话框">
	<p id="transfer_validateTips" style="color: #FF0000"></p>
	
	<form method="POST">
	<table cellspacing="0" class="yui-skin-sam noborder_table">
	<tbody>
		<tr>
			<th width="33%"><label for="transfer_dealDate"><font color="#FF0000">*&nbsp;</font>转账日期:</label></th>
			<td width="33%"><input type="text" id="transfer_dealDate" name="transfer_dealDate" maxlength="10" onclick="WdatePicker()" readonly="readonly" class="text ui-widget-content ui-corner-all"/>
				<input type="hidden" id="transfer_id" name="transfer_id" value="-1"/>
				<input type="hidden" id="transfer_inoutItem" name="transfer_inoutItem" value="3"/>
			</td>
			<td width="33%" class="memoText">格式：yyyy-MM-dd</td>
		</tr>
		<tr>
			<th><label for="transfer_money"><font color="#FF0000">*&nbsp;</font>转账金额:</label></th>
			<td><input type="text" id="transfer_money" name=transfer_money maxlength="10" onblur="moneyOnBlur('transfer_money','transfer_validateTips')" class="digital text ui-widget-content ui-corner-all"/></td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="transfer_out_account"><font color="#FF0000">*&nbsp;</font>转出账户:</label></th>
			<td>
				<select id="transfer_out_account" name="transfer_out_account" style="width: 100%">
					<%
						for(Iterator<AccountBase> it = accountMap.values().iterator(); it.hasNext();){
							AccountBase accountBase = (AccountBase)it.next();
							if(!"1".equals(accountBase.getType()) && !"2".equals(accountBase.getType())){// 账户类型：1.现金账户；2.银行账户；3.债权债务账户
								continue;
							}
					%>
							<option value="<%=accountBase.getId()%>"><%=accountBase.getName()%></option>
					<%
						}
					%>
				</select>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="transfer_in_account"><font color="#FF0000">*&nbsp;</font>转入账户:</label></th>
			<td>
				<select id="transfer_in_account" name="transfer_in_account" style="width: 100%">
					<%
						for(Iterator<AccountBase> it = accountMap.values().iterator(); it.hasNext();){
							AccountBase accountBase = (AccountBase)it.next();
							if(!"1".equals(accountBase.getType()) && !"2".equals(accountBase.getType())){// 账户类型：1.现金账户；2.银行账户；3.债权债务账户
								continue;
							}
					%>
							<option value="<%=accountBase.getId()%>"><%=accountBase.getName()%></option>
					<%
						}
					%>
				</select>
			</td>
			<td class="memoText"></td>
		</tr>
		<tr>
			<th><label for="transfer_relationUser"><font color="#FF0000">*&nbsp;</font>转账人:</label></th>
			<td>
				<select id="transfer_relationUser" name="transfer_relationUser" style="width: 100%" class="text ui-widget-content ui-corner-all">
				<%
				for(int i=0; i<relationUserList.size(); i++){
					RelationUser relationUser = (RelationUser)relationUserList.get(i);
					if(relationUser.getId().equals(userSession.getId())){
				%>
						<option value="<%=relationUser.getId()%>" selected="selected"><%=relationUser.getName()%></option>
				<%
					}else{
				%>
						<option value="<%=relationUser.getId()%>"><%=relationUser.getName()%></option>
				<%
					}
				}
				%>
				</select>
			</td>
			<td class="memoText">产生此转账项目的人</td>
		</tr>
		<tr>
			<th><label for="transfer_memo">备注:</label></th>
			<td><textarea id="transfer_memo" name="transfer_memo" rows="2" cols="18" class="text ui-widget-content ui-corner-all"></textarea></td>
			<td class="memoText"></td>
		</tr>
	</tbody>
	</table>
	</form>
</div><!-- 转账对话框 -->

<table id="tally_grid" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="tally_pager" class="scroll" style="text-align: center;"></div>

<script src="jsp/my/assistant/homecashmanager/tally/IndexTally.js"
	type="text/javascript"></script>
